<template>
<div>
    <gridView :url="url" :menuId="menuId" :treeObj="treeObj" 
        @otherClick="otherClick" 
        @verifyTopBar="verifyTopBar"></gridView>
    <addCommonly ref="addCommonly" :currentNodeData="currentNodeData"></addCommonly>
</div>
</template>


<script>

import gridView from "@/components/common/treeAndGridView.vue";
import addCommonly from "./addCommonly.vue";
var _this;
export default {
    data() {
        return {
            treeObj: {
                treeUrl:'/java/sys/menu/list',
                treeProps:{label:'name',isLeaf: true,children:'children'},
                searchProp:'menuId',
                nameProp:'name',
                parentPro:'parentId',
                initParam:{parentId:0},
                defaultExpandAll:false,
                lazy:true,
                title:'菜单树'
            },
            currentNodeData:null,
            url:'',
            menuId:1
        };
    },
    created() {
        _this = this;
        var url = _this.$route.path;
        url = '/java'+url.substring(0, url.lastIndexOf('index')-1);
        _this.url = url;
        _this.menuId = _this.$route.params.menuId;
    },
  
    mounted() {
    },
    methods: {
        verifyTopBar(obj, callback) {
            console.log('verifyTopBar', obj);
            if(obj.fun.code=='ADD' || obj.fun.code=='CYGN') {
                if(obj.currentNodeData == null) {
                    _this.$message({
                        showClose: true,
                        message: '请选择记录',
                        duration:3000,
                        type: 'error'
                    });
                } else {
                    _this.currentNodeData = obj.currentNodeData;
                    callback();
                }
            } else {
                callback();
            }
        },
        otherClick(fun, row) {
            if(fun.code=='CYGN') {
                _this.$refs.addCommonly.show(_this.currentNodeData.id);
            }
        }
    },
    components: { gridView, addCommonly }
};
</script>